package com.guchenbo.example.equals;

/**
 * 重载了Object.equals(),同时也重载了Object.hashCode()
 * <p/>
 * Created by CreGu on 2016/6/12.
 */
public class Person3 {
    private String name;
    private int age;

    public Person3(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public int hashCode() {
        return name.hashCode() * age;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof Person3)) {
            return false;
        }
        Person3 p = (Person3) obj;
        return p.name.equals(name) && p.age == age;
    }
}
